﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Trirand.Web.Mvc;

namespace EGym.Controllers
{
    public abstract partial class BaseController
    {
        #region Constantes
        private const string TEXTO_PAGINANDO = "Paginando";
        private const string TEXTO_CARREGANDO = "Carregando";
        private const string TEXTO_SEM_LINHAS = "Sem linhas";
        private const string STRING_PAGE_SIZE_OPTIONS = "[10,20,30,40,50,100,500,1000]";
        private const string TEXTO_LIMPAR = "Limpar";
        private const string TEXTO_PROCURAR = "Procurar";
        #endregion

        #region Metodos
        internal void BaseSetupJQGrid(JQGrid grdMain)
        {
            if (string.IsNullOrEmpty(grdMain.ID))
                grdMain.ID = "grdMain";

            BaseSetupJQGridDialogSettings(grdMain);

            BaseSetupJQGridMultiSelectSettings(grdMain);

            BaseSetupJQGridToolBarSettings(grdMain);

            BaseSetupJQGridSortSettings(grdMain);

            BaseSetupJQGridSearchDialogsSettings(grdMain);

            BaseSetupJQGridPagerSettings(grdMain);

            BaseSetupJQGridClientSideEventsSettings(grdMain);
        }

        private void BaseSetupJQGridDialogSettings(JQGrid grdMain)
        {
            BaseSetupJQGridEditDialogSettings(grdMain);

            BaseSetupJQGridAddDialogSettings(grdMain);

            BaseSetupJQGridDeleteDialogSettings(grdMain);
        }

        private void BaseSetupJQGridSortSettings(JQGrid grdMain)
        {
        }
        private void BaseSetupJQGridClientSideEventsSettings(JQGrid grdMain)
        {
            grdMain.ClientSideEvents.RowSelect = string.Format("{0}_onRowSelected", grdMain.ID);
        }

        private void BaseSetupJQGridDeleteDialogSettings(JQGrid grdMain)
        {
            grdMain.DeleteDialogSettings.LoadingMessageText = TEXTO_CARREGANDO;
        }

        private void BaseSetupJQGridEditDialogSettings(JQGrid grdMain)
        {
            grdMain.EditDialogSettings.CloseAfterEditing = true;
            grdMain.EditDialogSettings.LoadingMessageText = TEXTO_CARREGANDO;
        }

        private void BaseSetupJQGridAddDialogSettings(JQGrid grdMain)
        {
            grdMain.AddDialogSettings.LoadingMessageText = TEXTO_CARREGANDO;
            grdMain.AddDialogSettings.CloseAfterAdding = true;
        }

        private void BaseSetupJQGridMultiSelectSettings(JQGrid grdMain)
        {
            grdMain.MultiSelectMode = MultiSelectMode.SelectOnRowClick;
            grdMain.MultiSelect = false;
        }

        private void BaseSetupJQGridToolBarSettings(JQGrid grdMain)
        {
            grdMain.ToolBarSettings.ShowEditButton = false;
            grdMain.ToolBarSettings.ShowSearchToolBar = false;
            grdMain.ToolBarSettings.ShowSearchButton = true;
            grdMain.ToolBarSettings.ShowAddButton = false;
            grdMain.ToolBarSettings.ShowDeleteButton = false;
            grdMain.ToolBarSettings.ShowViewRowDetailsButton = true;
        }

        private void BaseSetupJQGridPagerSettings(JQGrid grdMain)
        {
            grdMain.PagerSettings.NoRowsMessage = TEXTO_SEM_LINHAS;
            grdMain.PagerSettings.PagingMessage = TEXTO_PAGINANDO;

            grdMain.PagerSettings.PageSize = 10;
            grdMain.PagerSettings.CurrentPage = 1;
            grdMain.PagerSettings.PageSizeOptions = STRING_PAGE_SIZE_OPTIONS;

        }

        private void BaseSetupJQGridSearchDialogsSettings(JQGrid grdMain)
        {

            grdMain.SearchDialogSettings.ResetButtonText = TEXTO_LIMPAR;
            grdMain.SearchDialogSettings.FindButtonText = TEXTO_PROCURAR;
        }

        #endregion
    }
}
